<template>
  <div id="invstorechange">
    <vxe-modal v-model="modelShow" width="55vw" show-footer :mask="false">
      <template #title>
        <span>切换仓库</span>
      </template>
      <template #default>
        <vxe-table ref="invStoreRef" show-overflow auto-resize height="300" :data="tableData" border="inner" :row-config="{isCurrent:true,isHover:true}">
          <vxe-column type="seq" width="30"></vxe-column>
          <vxe-column field="storeCode" title="编码" width="80"></vxe-column>
          <vxe-column field="storeName" title="名称" min-width="120pc"></vxe-column>
          <vxe-column field="level" title="级别" width="120" align="center"></vxe-column>
        </vxe-table>
      </template>
      <template #footer>
        <vxe-button @click="cancelEvent">关闭</vxe-button>
        <vxe-button status="primary" @click="confirmEvent">确定</vxe-button>
      </template>
    </vxe-modal>
  </div>
</template>
<script setup lang="ts">
import { ref, reactive, getCurrentInstance, watch, onMounted } from 'vue';
import { pageSizes, DateToString, formatDateTime, IsEmpty } from '@/utils/common';
import { VxeMessage, VxeNotifyType } from '@/utils/CommonMessage';
import { VXETable } from 'vxe-table';
import XEUtils from 'xe-utils';
import { AppStore } from '@/stores/store';
import axios from 'axios';

// 全局变量定义区 ==========
let { proxy }: any = getCurrentInstance();
let store = AppStore();
let modelShow = ref(false);
let showLoading = ref(false);
let tableData = reactive([]);
let loading = ref(false);/** 列表加载 */
const invStoreRef = ref(null);/**仓库列表对象 */

defineExpose({
  initPage/**显示弹窗 */
});

onMounted(() => {
});

function initPage() {
  modelShow.value = true;
  findStoreList();
}

/**查询仓库信息 */
function findStoreList() {
  loading.value = true;
  tableData.length = 0;
  const url = '/inv/storeManage/findStoreManageList';
  proxy.$http
    .get(url, { params: { storeId: null, searchValue: '' } })
    .then((res: any) => {
      tableData.length = 0;
      tableData.push(...res.data);
      loading.value = false;
    })
    .catch((err: any) => {
      loading.value = false;
      VxeMessage('查询列表失败', VxeNotifyType.error);
    });
}

function cancelEvent() {
  modelShow.value = false;
}

/**确定切换库存 */
function confirmEvent() {
  const row = invStoreRef.value?.getCurrentRecord();
  if (row && !IsEmpty(row.id)) {
    const obj = Object.assign({}, row);
    store.setCurInvStoreObj(obj);
    modelShow.value = false;
  }
  else {
    VxeMessage('请先选中需要切换的仓库', VxeNotifyType.warning);
  }
}
</script>
<style lang="scss" scope>
#invstorechange {
}
</style>